package com.wutianyi.jackson;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.ser.StdSerializerProvider;
import org.codehaus.jackson.type.TypeReference;

public class FullDataBinding
{
    public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException
    {
        ObjectMapper mapper = new ObjectMapper();
        User user = mapper.readValue(FullDataBinding.class.getResourceAsStream("/user.json"), User.class);
        StdSerializerProvider sp = new StdSerializerProvider();
        mapper.writeValue(new File("user.json"), user);
        // simple type的处理
        Map<String, Object> userData = mapper.readValue(FullDataBinding.class.getResourceAsStream("/user.json"),
                Map.class);
        mapper.writeValue(new File("user-modified.json"), userData);
        // 指定映射的类型
        Map<String, User> result = mapper.readValue(new File(""), new TypeReference<Map<String, User>>()
        {
        });
    }
}
